package com.epam.debrecen.hackathon.ai;

import com.epam.debrecen.hackathon.ai.model.State;
import java.util.PriorityQueue;

public class Resolver {

	private PriorityQueue<State> unprocessedStates = new PriorityQueue<State>();
	private State currentState;
	private int maxDepth = 1;

	public State process(State state) {
		unprocessedStates.clear();
		unprocessedStates.addAll(state.getPossibleStates());
		currentState = unprocessedStates.poll();
		return currentState;
	}

	private void startProcess() {
		currentState = unprocessedStates.poll();
		unprocessedStates.addAll(currentState.getChildren());
		State nextState = null;
		while ((nextState = unprocessedStates.poll()) != null) {
			if (nextState.getValue() > currentState.getValue()) {
				currentState = nextState;
				if (currentState.getDepth() > maxDepth) {
					unprocessedStates.addAll(currentState.getChildren());
				}
			}
		}
	}
}
